package com.teach.controller.photo;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.teach.R;
import com.teach.dto.LoginUser;
import com.teach.entity.PhotoFav;
import com.teach.service.photo.PhotoFivService;

@RestController
@RequestMapping("/photo")
public class PhotoFavController {
 
	@Autowired
	private PhotoFivService service; 
	
	@RequestMapping("/fav.do")
	public Object doFav(LoginUser user,
			@RequestParam("picId")Long picId,
			@RequestParam("title")String title,
			@RequestParam("writerId")String writerId,
			@RequestParam("picClassId")Long picClassId) {
		PhotoFav fav = new PhotoFav();
		fav.setPhotoFavUserId(user.getUserName());
		fav.setPhotoPicId(picId);
		fav.setPhotoFavStatus("已收藏");
		fav.setPhotoFavTime(new Date());
		return service.insertSelective(fav);
	}
	@RequestMapping("/removeFav.do")
	public Object doRemoveFav(LoginUser user,
			@RequestParam("picId")Long picId,
			@RequestParam("title")String title,
			@RequestParam("writerId")String writerId,
			@RequestParam("picClassId")Long picClassId) {
		PhotoFav fav = new PhotoFav();
		fav.setPhotoPicId(picId);
		fav.setPhotoFavStatus("取消收藏");
		return service.updateStatus(fav.getPhotoFavStatus(), picId, user.getUserName());
	}
}
